package edu.jabs.patientsCentral.gui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

/**
 * Extension Panel
 */
public class ExtensionPanel extends JPanel implements ActionListener
{

    // -----------------------------------------------------------------
    // Constants
    // -----------------------------------------------------------------

    /**
     * Command option 1
     */
    private static final String OPTION_1 = "OPTION_1";

    /**
     * Command option 2
     */
    private static final String OPTION_2 = "OPTION_2";

    /**
     * Command option 3
     */
    private static final String OPTION_3 = "OPTION_3";

    /**
     * Command option 4
     */
    private static final String OPTION_4 = "OPTION_4";

    /**
     * Command option 4
     */
    private static final String OPTION_5 = "OPTION_5";

    // -----------------------------------------------------------------
    // Fields
    // -----------------------------------------------------------------

    /**
     * Application main window
     */
    private PatientsCentralGUI principal;

    // -----------------------------------------------------------------
    // GUI Fields
    // -----------------------------------------------------------------

    /**
     * Option 1 Button
     */
    private JButton btnOption1;

    /**
     * Option 2 Button
     */
    private JButton btnOption2;

    /**
     * Option 3 Button
     */
    private JButton btnOption3;

    /**
     * Option 4 Button
     */
    private JButton btnOption4;

    /**
     * Option 5 Button
     */
    private JButton btnOption5;

    // -----------------------------------------------------------------
    // Constructors
    // -----------------------------------------------------------------

    /**
     * It builds the Panel
     * @param window Main window
     */
    public ExtensionPanel( PatientsCentralGUI window )
    {
        principal = window;

        setBorder( new TitledBorder( "Options" ) );
        setLayout( new GridBagLayout( ) );

        // Option 1 Button
        btnOption1 = new JButton( "Option 1" );
        btnOption1.setActionCommand( OPTION_1 );
        btnOption1.addActionListener( this );
        GridBagConstraints gbc = new GridBagConstraints( );
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets( 0, 0, 0, 5 );
        add( btnOption1, gbc );

        // Option 2 Button
        btnOption2 = new JButton( "Option 2" );
        btnOption2.setActionCommand( OPTION_2 );
        btnOption2.addActionListener( this );
        gbc = new GridBagConstraints( );
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.insets = new Insets( 0, 0, 0, 5 );
        add( btnOption2, gbc );

        // Option 3 Button
        btnOption3 = new JButton( "Option 3" );
        btnOption3.setActionCommand( OPTION_3 );
        btnOption3.addActionListener( this );
        gbc = new GridBagConstraints( );
        gbc.gridx = 2;
        gbc.gridy = 0;
        gbc.insets = new Insets( 0, 0, 0, 5 );
        add( btnOption3, gbc );

        // Option 4 Button
        btnOption4 = new JButton( "Option 4" );
        btnOption4.setActionCommand( OPTION_4 );
        btnOption4.addActionListener( this );
        gbc = new GridBagConstraints( );
        gbc.gridx = 3;
        gbc.gridy = 0;
        gbc.insets = new Insets( 0, 0, 0, 5 );
        add( btnOption4, gbc );

        // Option 5 Button
        btnOption5 = new JButton( "Option 5" );
        btnOption5.setActionCommand( OPTION_5 );
        btnOption5.addActionListener( this );
        gbc = new GridBagConstraints( );
        gbc.gridx = 4;
        gbc.gridy = 0;
        gbc.insets = new Insets( 0, 0, 0, 5 );
        add( btnOption5, gbc );
    }

    // -----------------------------------------------------------------
    // Methods
    // -----------------------------------------------------------------

    /**
     * Handling button events
     * @param e Action generated by the event.
     */
    public void actionPerformed( ActionEvent e )
    {
        if( OPTION_1.equals( e.getActionCommand( ) ) )
        {
            principal.reqFuncOption1( );
        }
        else if( OPTION_2.equals( e.getActionCommand( ) ) )
        {
            principal.reqFuncOption2( );
        }
        else if( OPTION_3.equals( e.getActionCommand( ) ) )
        {
            principal.reqFuncOption3( );
        }
        else if( OPTION_4.equals( e.getActionCommand( ) ) )
        {
            principal.reqFuncOption4( );
        }
        else if( OPTION_5.equals( e.getActionCommand( ) ) )
        {
            principal.reqFuncOption5( );
        }

    }

}